package com.lening.utils;

import com.lening.entity.StuBean;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import java.util.List;

public class ExportExcel {

	public static void getExportExcel(HSSFWorkbook work, List<StuBean> list){
		
		 HSSFSheet sheet = work.createSheet("学生列表");
		 //设置表头
		 HSSFRow row = sheet.createRow(0);
		 row.createCell(0).setCellValue("学生ID");
		 row.createCell(1).setCellValue("学生姓名");
		 row.createCell(2).setCellValue("家庭住址");
		 row.createCell(3).setCellValue("班级");
		 //添加数据
		 for(int i=0;i<list.size();i++){
			 HSSFRow r = sheet.createRow(i+1);
			 StuBean stu = list.get(i);
			 r.createCell(0).setCellValue(stu.getId());
			 r.createCell(1).setCellValue(stu.getSname());
			 r.createCell(2).setCellValue(stu.getAddress());
			 r.createCell(3).setCellValue(stu.getGb().getGname());
		 }
		sheet = null;
		row = null;
	}
}
